﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/Static/demo.css" rel="stylesheet" type="text/css" />
    <script src="/Static/boot.js" type="text/javascript"></script>
    <link href="/Static/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td>
                    <label style="font-family: Verdana;">
                        By Order No.:
                    </label>
                    <input class="mini-textbox" id="txt_OrderNO" />
                    <label style="font-family: Verdana;">
                        By Brand Name:
                    </label>
                    <input class="mini-textbox" id="txt_brandName" />
                    <label style="font-family: Verdana;">
                        By Model Name:
                    </label>
                    <input class="mini-textbox" id="txt_productModel" />
                    <label style="font-family: Verdana;">
                        By Payment Date:
                    </label>
                    <input class="mini-datepicker" id="txt_OrderDateStart" width="100px" />
                    -
                    <input class="mini-datepicker" id="txt_OrderDateEnd" width="100px" />
                    Type:
                    <input id="productType" style="width: 80px" name="productType" class="mini-combobox" textfield="text" valuefield="id" emptytext="Pls select..."
                           value="" allowinput="false" shownullitem="true" url="/ConfigData/ProductType.txt" nullitemtext="Pls select..." />
                    <br />
                    <label style="font-family: Verdana;">
                        Product Name
                    </label>
                    <input class="mini-textbox" id="txt_productName" />
                    <label style="font-family: Verdana;">
                        Wty Eff.Date:
                    </label>
                    <input class="mini-datepicker" id="txt_ServiceStartStart" width="100px" />
                    -
                    <input class="mini-datepicker" id="txt_ServiceStartEnd" width="100px" />
                    <label style="font-family: Verdana;">
                        Wty Exp.Date
                    </label>
                    <input class="mini-datepicker" id="txt_ServiceEndStart" width="100px" />
                    -
                    <input class="mini-datepicker" id="txt_ServiceEndEnd" width="100px" />
                    <label style="font-family: Verdana;">
                        Country
                    </label>
                    <input class="mini-textbox" id="txt_country" width="50px" />
                    <label id="warrantyTypeLabel" style="font-family: Verdana;">
                        WarrantyType:
                    </label>
                    <input id="warrantyTypeSelect" name="warrantyTypeSelect" class="mini-combobox" textfield="text" valuefield="id" emptytext="Pls select..."
                           value="" allowinput="false" shownullitem="true" url="/ConfigData/WarrantyType.txt" nullitemtext="Pls select..." onvaluechanged="AllocationSullpierChange" />
                    <br />
                    <span id="sAdmin" style="display: none">
                        <label id="supplierLabel" style="font-family: Verdana;">
                            By Supplier:
                        </label>
                        <input  id="supplierSelect" name="AllocationSullpier" class="mini-combobox" textfield="text" style="width: 80px" valuefield="id" emptytext="Pls select..."
                                value="" allowinput="false" shownullitem="true" url="/ConfigData/AllocationSupplier.txt" nullitemtext="Pls select..." onvaluechanged="AllocationSullpierChange" />

                        <input id="supSelect" style="display: none" name="Supplier" class="mini-combobox" style="width: 80px" textfield="SupplierName" valuefield="ID" emptytext="Pls select..."
                               value="" allowinput="false" shownullitem="true" url="/Ajax/AjaxService.aspx?method=GetAliSupplier&isActive=Y&pageIndex=0&sortField=ID" nullitemtext="Pls select..." />

                        <label style="font-family: Verdana;">
                            Effective:
                        </label>
                        <input id="effectiveSelect" style="width: 80px" name="effectiveSelect" class="mini-combobox" textfield="text" valuefield="id" emptytext="Pls select..."
                               value="" allowinput="false" shownullitem="true" url="/ConfigData/Effective.txt" nullitemtext="Pls select..." />
                        <label style="font-family: Verdana;">
                            Effective Date
                        </label>
                        <input class="mini-datepicker" id="txt_EffectiveDateStart" width="100px" />
                        -
                        <input class="mini-datepicker" id="txt_EffectiveDateEnd" width="100px" />
                        Wty Status
                        <input id="warrantyStatus" style="width: 80px" name="warrantyStatus" class="mini-combobox" textfield="text" valuefield="id" emptytext="Pls select..."
                               value="" allowinput="false" shownullitem="true" url="/ConfigData/WarrantyStatus.txt" nullitemtext="Pls select..." />
                        OrderFromType
                        <input id="orderFromType" name="orderFromType" class="mini-combobox" textfield="Value" valuefield="Key" emptytext="Pls select..."
                               value="" allowinput="false" shownullitem="true" url="/Ajax/AjaxService.aspx?method=GetOrderFromType" nullitemtext="Pls select..." style="width: 80px" />
                        <label style="font-family: Verdana;">
                            HasIssue:
                        </label>
                        <input id="hasIssue" style="width: 80px" name="hasIssue" class="mini-combobox" textfield="text" valuefield="id" emptytext="Pls select..."
                               value="" allowinput="false" shownullitem="true" url="/ConfigData/Effective.txt" nullitemtext="Pls select..." />
                        <label style="font-family: Verdana;"></label>
</span>
                    <a class="mini-button" iconcls="icon-search" onclick="searchList()">Search</a> <a class="mini-button"
                                                                                                  iconcls="icon-remove" onclick="clear()">Reset</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:60%;">
                    <a class="mini-button" style="display: none" id="btnEdit" onclick="EditOrder()">Edit</a>
                    <a class="mini-button" onclick="SaveData()">Save</a>
                    <a class="mini-button" style="display: none" id="btnSupplier" onclick="AllocationSupplier()"> Allocate</a>
                    <a class="mini-button"  id="btnSyncParData" onclick="SyncParData()">Sync Appointed</a>
                    <a class="mini-button" style="display: none" id="btnSyncAliData" onclick="SyncAliData()">Sync All</a>
                    <a class="mini-button" id="btnExportExcel" style="display: none" onclick="ExportExcel()">Export Excel</a>
                </td>
                <td style="width: 40%;padding-right:10px;display: none" id="totalReport">
                    订单总金额：<span id="productTotalAmount"></span>&nbsp;USD &nbsp;&nbsp;
                    保修总金额：<span id="serviceTotalAmount"></span>&nbsp;USD&nbsp;&nbsp;
                    总数量：<span id="ProductCount"></span>
                </td>
            </tr>
        </table>
    </div>
    <!--onrowdblclick="EditOrder"-->
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 80%;" url="/Ajax/AjaxService.aspx?method=GetAliOrder" multiselect="true"  ondrawcell="onDrawCell"
         idfield="ID" sizelist="[5,10,20,50,100,500]" pagesize="20" allowcelledit="true" allowcellselect="true" multiselect="true">
        <div property="columns">
            <div type="checkcolumn">
            </div>
            <div type="indexcolumn">
            </div>
            <!--<div field="Maintenance" width="120" headeralign="center" allowsort="true">
                    维修记录
                </div>-->
            <div field="OrderId" width="110" headeralign="center" allowsort="true">
                Order No.
            </div>
            <div field="SupplierName" width="120" headeralign="center" allowsort="true">
                Supplier
            </div>
            <div field="OrderDate" width="120" headeralign="center" dateformat="yyyy-MM-dd HH:mm" allowsort="true">
                Order Date
            </div>
            <div field="EffectiveDate" width="120" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm">
                Effective Date
            </div>
            <div field="ServiceStartTime" width="120" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm">
                Wty Start Date
            </div>
            <div field="ServiceEndTime" width="120" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm">
                Wty End Date
            </div>
            <div field="ProductName" width="100" allowsort="true">
                ProductName
            </div>
            <div field="BrandName" width="80" align="center" headeralign="center" allowsort="true">
                Brand
                <input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="ProductModel" width="80" align="center" headeralign="center" allowsort="true">
                Model
                <input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <div field="ProductAmount" width="80" align="center" headeralign="center" allowsort="true">
                Order Price(USD)
            </div>
            <div field="ProductCount" width="50" align="center" headeralign="center" allowsort="true">
                Qty
            </div>
            <div field="ServiceAmount" width="80" align="center" headeralign="center" allowsort="true">
                Warranty Price(USD)
            </div>
            <div field="ProductType" width="80" align="center" headeralign="center">
                Product Type
            </div>
            <div field="OrderFromType" width="80" align="center" headeralign="center">
                OrderFromType
            </div>
            <div field="enlink" width="80" align="center" headeralign="center">
                URL(En)
            </div>
            <div field="rulink" width="80" align="center" headeralign="center">
                URL(Ru)
            </div>
            <div field="OrderCurrency" width="60" align="center" headeralign="center">
                Order Cy.
            </div>
            <div field="PayCurrency" width="60" align="center" headeralign="center" allowsort="true">
                Payment Cy.
            </div>
            <div field="ItemCondition" width="100" align="center" headeralign="center" allowsort="true">
                Item Condition
            </div>
            <div field="RAM" width="100" align="center" headeralign="center" allowsort="true">
                RAM
            </div>
            <div field="ROM" width="100" align="center" headeralign="center" allowsort="true">
                ROM
            </div>
            <div field="DisplaySize" width="100" align="center" headeralign="center" allowsort="true">
                Display Size
            </div>
            <div field="DisplayResolution" width="100" align="center" headeralign="center" allowsort="true">
                Display Res
            </div>
            <div field="BatteryCapacity" width="100" align="center" headeralign="center" allowsort="true">
                Battery Cap.
            </div>
            <div field="CPU" width="100" align="center" headeralign="center" allowsort="true">
                CPU
            </div>
            <div field="Size" width="100" align="center" headeralign="center" allowsort="true">
                Body Size
            </div>
            <div field="OperationSystem" width="100" align="center" headeralign="center" allowsort="true">
                OperationSystem
            </div>
            <div field="OS" width="100" align="center" headeralign="center">
                OS
            </div>
            <!--<div field="ProductIMEI" width="100" align="center" headeralign="center">
                    ProductIMEI
                </div>
                <div field="ProductSN" width="100" allowsort="true">
                    ProductSN
                </div>
                <div field="ProductName" width="100" allowsort="true">
                    ProductName
                </div>
                <div field="ProductSkuInfo" width="100" headeralign="center" allowsort="true">
                    ProductSkuInfo
                </div>
                <div field="ProductSnapshotUrl" width="100" headeralign="center" allowsort="true">
                    ProductSnapshotUrl
                </div>
                <div field="StoreUrl" width="100" headeralign="center" allowsort="true">
                    StoreUrl
                </div>
                <div field="Telephone" width="120" headeralign="center" allowsort="true">
                    Telephone
                </div>
                <div field="Name" width="120" headeralign="center" allowsort="true">
                    Name
                </div>
                <div field="Country" width="120" headeralign="center" allowsort="true">
                    Country
                </div>
                <div field="Province" width="120" headeralign="center" allowsort="true">
                    Province
                </div>
                <div field="City" width="120" headeralign="center" allowsort="true">
                    City
                </div>
                <div field="County" width="120" headeralign="center" allowsort="true">
                    County
                </div>
                <div field="StreetAddress" width="120" headeralign="center" allowsort="true">
                    StreetAddress
                </div>
                <div field="PostCode" width="120" headeralign="center" allowsort="true">
                    PostCode
                </div>
                <div field="SendGoodsTime" width="120" headeralign="center" allowsort="true">
                    SendGoodsTime
                </div>
                <div field="SellerIDGetGoodsTime" width="120" headeralign="center" allowsort="true">
                    SellerIDGetGoodsTime
                </div>
                <div field="SellerFamilyName" width="120" headeralign="center" allowsort="true">
                    SellerFamilyName
                </div>-->
            <div field="Telephone" width="100" headeralign="center" allowsort="true">
                Buyer Phone
            </div>
            <div field="Name" width="100" headeralign="center" allowsort="true">
                Buyer Name
            </div>
            <div field="Country" width="100" headeralign="center" allowsort="true">
                Buyer Country
            </div>
            <div field="Province" width="100" headeralign="center" allowsort="true">
                Buyer Province
            </div>
            <div field="City" width="100" headeralign="center" allowsort="true">
                Buyer City
            </div>
        <div field="StreetAddress" width="100" headeralign="center" allowsort="true">
            Buyer StreetAddress
        </div>
            <div field="SendGoodsTime" width="130" headeralign="center" dateformat="yyyy-MM-dd HH:mm:ss" allowsort="true">
                Delivery time
        </div>
        <div field="SellerIDGetGoodsTime" width="130" headeralign="center" dateformat="yyyy-MM-dd HH:mm:ss" allowsort="true">
            Receiving Time
        </div>
            <div field="ProductIMEI" width="100" align="center" headeralign="center" vtype="" allowsort="true">
                IMEI
                <input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>
            <!--<div field="ProductSN" width="100" allowsort="true" vtype="">
                SN
                <input property="editor" class="mini-textbox" style="width: 100%;" />
            </div>-->
            <div field="Description" width="100" headeralign="center" allowsort="true">
                Description
            </div>
            <div field="ENid" width="100" headeralign="center" allowsort="true">
                ENid
            </div>
            <div field="BizID" width="100" headeralign="center" allowsort="true">
                BizID
            </div>
            <div field="EnterSysTime" width="130" headeralign="center" dateformat="yyyy-MM-dd HH:mm:ss" allowsort="true">
                EnterSysTime
            </div>
            <div field="BuyerAliId" width="130" headeralign="center" >
                BuyerAliId
            </div>
            <div field="SellerAliId" width="130" headeralign="center" allowsort="true">
                SellerAliId
            </div>
            <div field="IssueId" width="130" headeralign="center" allowsort="true">
                IssueId
            </div>
            <div field="IssueStatus" width="130" headeralign="center" allowsort="true">
                IssueStatus
            </div>
            <div field="RefundMoneyAmount" width="130" headeralign="center" allowsort="true">
                RefundMoneyAmount
            </div>
            <div field="RefundMoneyAmountCurrency" width="130" headeralign="center" allowsort="true">
                RefundMoneyAmountCurrency
            </div>
            <div field="CreateTime" width="130" headeralign="center" allowsort="true" dateformat="yyyy-MM-dd HH:mm:ss">
                CreateTime
            </div>
        </div>
    </div>
    <!--导出Excel相关HTML-->
    <form id="excelForm" action="/Ajax/export.aspx?type=Ali" method="post" target="excelIFrame">
        <input type="hidden" name="columns" id="excelData" />

        <input type="hidden" name="orderid" id="orderNOHidden" />
        <input type="hidden" name="orderDateStart" id="orderStartDateHidden" />
        <input type="hidden" name="orderDateEnd" id="orderEndDateHidden" />
        <input type="hidden" name="isAllocation" id="isAllocationHidden" />
        <input type="hidden" name="supplierID" id="supplierIDHidden" />
        <input type="hidden" name="brandName" id="brandNameHidden" />
        <input type="hidden" name="productModel" id="productModelHidden" />
        <input type="hidden" name="warrantyTypeSelect" id="warrantyTypeSelectHidden" />
        <input type="hidden" name="serviceStartStart" id="serviceStartStartHidden" />
        <input type="hidden" name="serviceStartEnd" id="serviceStartEndHidden" />
        <input type="hidden" name="serviceEndStart" id="serviceEndStartHidden" />
        <input type="hidden" name="serviceEndEnd" id="serviceEndEndHidden" />
        <input type="hidden" name="country" id="countryHidden" />
        <input type="hidden" name="effectiveSelect" id="effectiveSelectHidden" />
        <input type="hidden" name="effectiveDateStart" id="effectiveDateStartHidden" />
        <input type="hidden" name="effectiveDateEnd" id="effectiveDateEndHidden" />
        <input type="hidden" name="warrantyStatus" id="warrantyStatusHidden" />
        <input type="hidden" name="productType" id="productTypeHidden"/>
        <input type="hidden" name="orderFromType" id="orderFromTypeHidden"/>
        <input type="hidden" name="hasIssue" id="hasIssueHidden" />
    </form>
    <iframe id="excelIFrame" name="excelIFrame" style="display: none;"></iframe>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.sortBy("ID", "DESC");
        grid.load();
        GetAmount();


        mini.get("txt_OrderDateStart").setAllowInput(false);
        mini.get("txt_OrderDateEnd").setAllowInput(false);
        mini.get("txt_ServiceStartStart").setAllowInput(false);
        mini.get("txt_ServiceStartEnd").setAllowInput(false);
        mini.get("txt_ServiceEndStart").setAllowInput(false);
        mini.get("txt_ServiceEndEnd").setAllowInput(false);
        mini.get("txt_EffectiveDateStart").setAllowInput(false);
        mini.get("txt_EffectiveDateEnd").setAllowInput(false);

        
        //$.ajax({
        //    url: "/Ajax/AjaxService.aspx?method=GetSession",
        //    success: function (text) {
        //        var result = $.parseJSON(text);
        //        if (result.IsAdmin == "Y") {
        //            $("#btnEdit").show();
        //            $("#btnSupplier").show(); 
        //            //$("#btnSyncParData").show();
        //            $("#btnSyncAliData").show();
        //            $("#sAdmin").show();
        //        } else {
        //            $("#btnEdit").hide();
        //            $("#btnSupplier").hide();
        //            //$("#btnSyncParData").hide();
        //            $("#btnSyncAliData").hide();
        //            $("#sAdmin").show();
        //        }
        //        if (result.CanExportAllData) {
        //            $("#totalReport").show();
        //            $("#btnExportExcel").show();
        //        }
        //    },
        //    error: function () {
        //    }
        //});

        function unfixColumns() {
            grid.unFrozenColumns();
        }
        function fixColumns() {
            grid.frozenColumns(0, 1);
        }
        //去空格
        function trimStr(str) {
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
        //清空条件
        function clear() {
            mini.get("txt_OrderNO").setValue("");
            mini.get("txt_OrderDateStart").setValue("");
            mini.get("txt_OrderDateEnd").setValue("");
            mini.get("txt_brandName").setValue("");
            mini.get("txt_productModel").setValue("");
            mini.get("productType").setValue("");
            mini.get("txt_OrderDateEnd").setValue("");
            mini.get("txt_ServiceStartStart").setValue("");
            mini.get("txt_ServiceStartEnd").setValue("");
            mini.get("txt_ServiceEndStart").setValue("");
            mini.get("txt_ServiceEndEnd").setValue(""); 
            mini.get("txt_country").setValue("");
            mini.get("warrantyTypeSelect").setValue(""); 
            mini.get("supplierSelect").setValue(""); 
            mini.get("supSelect").setValue(""); 
            mini.get("effectiveSelect").setValue("");
            mini.get("txt_EffectiveDateStart").setValue("");
            mini.get("txt_EffectiveDateEnd").setValue("");
            mini.get("warrantyStatus").setValue("");
            mini.get("txt_productName").setValue("");
        }
        //查询
        function searchList() {
            GetAmount();
            var orderid = trimStr(mini.get("txt_OrderNO").getValue());
            var orderDateStart = mini.get("txt_OrderDateStart").getFormValue();
            var orderDateEnd = mini.get("txt_OrderDateEnd").getFormValue();
            var isAllocation = mini.getbyName("AllocationSullpier").getValue();
            var supplierID = mini.get("supSelect").getValue();
            var brandName = mini.get("txt_brandName").getValue();
            var productModel = mini.get("txt_productModel").getValue();

            var warrantyType = mini.getbyName("warrantyTypeSelect").getValue();
            

            var serviceStartStart = mini.get("txt_ServiceStartStart").getFormValue();
            var serviceStartEnd = mini.get("txt_ServiceStartEnd").getFormValue();
            var serviceEndStart = mini.get("txt_ServiceEndStart").getFormValue();
            var serviceEndEnd = mini.get("txt_ServiceEndEnd").getFormValue();
            
            var country = mini.get("txt_country").getValue();

            var effectiveSelect = mini.get("effectiveSelect").getValue();
            var effectiveDateStart = mini.get("txt_EffectiveDateStart").getFormValue(); 
            var effectiveDateEnd = mini.get("txt_EffectiveDateEnd").getFormValue();
            var warrantyStatus = mini.get("warrantyStatus").getFormValue();
            var productType = mini.getbyName("productType").getValue(); 
            var orderFromType = mini.getbyName("orderFromType").getValue();
            var hasIssue = mini.getbyName("hasIssue").getValue();
            
            var productName = trimStr(mini.get("txt_productName").getValue());
            
            
            grid.load({ orderid: orderid, orderDateStart: orderDateStart, orderDateEnd: orderDateEnd, isAllocation: isAllocation, supplierID: supplierID, brandName: brandName, productModel: productModel, warrantyType: warrantyType, serviceStartStart: serviceStartStart, serviceStartEnd: serviceStartEnd, serviceEndStart: serviceEndStart, serviceEndEnd: serviceEndEnd, country: country, effectiveSelect: effectiveSelect, effectiveDateStart: effectiveDateStart, effectiveDateEnd: effectiveDateEnd, warrantyStatus: warrantyStatus, productType: productType, orderFromType: orderFromType, hasIssue: hasIssue, productName: productName });
        }
        function GetAmount() {
            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=GetSession",
                success: function (text) {
                    var result = $.parseJSON(text);
                    if (result.IsAdmin == "Y") {
                        $("#btnEdit").show();
                        $("#btnSupplier").show();
                        //$("#btnSyncParData").show();
                        $("#btnSyncAliData").show();
                        $("#sAdmin").show();
                    } else {
                        $("#btnEdit").hide();
                        $("#btnSupplier").hide();
                        //$("#btnSyncParData").hide();
                        $("#btnSyncAliData").hide();
                        $("#sAdmin").show();
                    }
                    if (result.CanExportAllData) {
                        $("#totalReport").show();
                        $("#btnExportExcel").show();
                    }

                    if (result.error != null && result.error != undefined && result.error == -1) {
                        window.parent.location.href = '/Login.aspx';
                    }
                },
                error: function () {
                }
            });


            var orderid = trimStr(mini.get("txt_OrderNO").getValue());
            var orderDateStart = mini.get("txt_OrderDateStart").getFormValue();
            var orderDateEnd = mini.get("txt_OrderDateEnd").getFormValue();
            var isAllocation = mini.getbyName("AllocationSullpier").getValue();
            var supplierID = mini.get("supSelect").getValue();
            var brandName = mini.get("txt_brandName").getValue();
            var productModel = mini.get("txt_productModel").getValue();
            
            var warrantyType = mini.getbyName("warrantyTypeSelect").getValue();
            var serviceStartStart = mini.get("txt_ServiceStartStart").getFormValue();
            var serviceStartEnd = mini.get("txt_ServiceStartEnd").getFormValue();
            var serviceEndStart = mini.get("txt_ServiceEndStart").getFormValue();
            var serviceEndEnd = mini.get("txt_ServiceEndEnd").getFormValue();
            var warrantyStatus = mini.get("warrantyStatus").getValue();
            
            var country = mini.get("txt_country").getValue();
            
            var effectiveSelect = mini.get("effectiveSelect").getValue();
            var effectiveDateStart = mini.get("txt_EffectiveDateStart").getFormValue();
            var effectiveDateEnd = mini.get("txt_EffectiveDateEnd").getFormValue();
            var productType = mini.getbyName("productType").getValue();
            var orderFromType = mini.getbyName("orderFromType").getValue();
            var hasIssue = mini.getbyName("hasIssue").getValue();
            var productName = trimStr(mini.get("txt_productName").getValue());
            
            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=GetTotalAmount",
                data: { orderid: orderid, orderDateStart: orderDateStart, orderDateEnd: orderDateEnd, isAllocation: isAllocation, supplierID: supplierID, brandName: brandName, productModel: productModel, warrantyType: warrantyType, serviceStartStart: serviceStartStart, serviceStartEnd: serviceStartEnd, serviceEndStart: serviceEndStart, serviceEndEnd: serviceEndEnd, country: country, effectiveSelect: effectiveSelect, effectiveDateStart: effectiveDateStart, effectiveDateEnd: effectiveDateEnd, warrantyStatus: warrantyStatus, productType: productType, orderFromType: orderFromType, hasIssue: hasIssue, productName: productName },
                cache: false,
                type: 'post',
                success: function (text) {
                    
                    var result = $.parseJSON(text);
                    document.getElementById("productTotalAmount").innerText = result.ProductTotalAmount == undefined ? 0 : result.ProductTotalAmount;
                    document.getElementById("serviceTotalAmount").innerText = result.ServiceTotalAmount == undefined ? 0 : result.ServiceTotalAmount;
                    //ProductCount
                    document.getElementById("ProductCount").innerText = result.ProductCount == undefined ? 0 : result.ProductCount;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(jqXHR.responseText);
                }
            });
        }
        $("#txt_OrderNO").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });
        $("#txt_brandName").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });
        $("#txt_productModel").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });
        $("#txt_OrderDateStart").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });
        $("#txt_OrderDateEnd").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                searchList();
            }
        });

        function SyncAliData() {
            try {
                var rows = grid.getSelecteds();
                if (rows.length > 0) {
                    var ids = [];
                    var orderIds = [];
                    var enIds = [];
                    var bzIds = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.ID);
                        orderIds.push(r.OrderId);
                        enIds.push(r.ENid);
                        bzIds.push(r.BizID);
                    }
                    var id = ids.join(',');
                    var orderId = orderIds.join(',');
                    var enId = enIds.join(',');
                    var bizIds = bzIds.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/Ajax/AjaxService.aspx?method=SyncAliData",
                        data: { ids: id, orderIds: orderId, enIds: enId, bizIds: bizIds },
                        cache: false,
                        type:'post',
                        success: function (text) {
                            var result = $.parseJSON(text);

                            var str = "同步成功数量：" + result.successCount;
                            if (result.failCount != 0) {
                                str = str + "  失败数量：" + result.failCount;
                                str = str +"\r\n"+ result.error;
                            }
                            mini.alert(str);

                            //if (result.res != "操作成功") {
                            //    mini.alert("操作失败!");
                                
                            //}
                            //searchList();
                            grid.reload();
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert(jqXHR.responseText);
                        }
                    });

                } else {
                    mini.alert("请选择要同步的订单!");
                }
            }
            catch (e) {
                mini.alert("请选择要同步的订单!");
                return false;
            }
        }
        
        function SyncParData() {
            try {
                var rows = grid.getSelecteds();
                if (rows.length > 0) {
                    var ids = [];
                    var orderIds = [];
                    var enIds = [];
                    var bzIds = [];
                    for (var i = 0, l = rows.length; i < l; i++) {
                        var r = rows[i];
                        ids.push(r.ID);
                        orderIds.push(r.OrderId);
                        enIds.push(r.ENid);
                        bzIds.push(r.BizID);
                    }
                    var id = ids.join(',');
                    var orderId = orderIds.join(',');
                    var enId = enIds.join(',');
                    var bizIds = bzIds.join(',');
                    grid.loading("操作中，请稍后......");
                    $.ajax({
                        url: "/Ajax/AjaxService.aspx?method=SyncParData",
                        data: { ids: id, orderIds: orderId, enIds: enId, bizIds: bizIds },
                        cache: false,
                        type: 'post',
                        success: function (text) {
                            var result = $.parseJSON(text);

                            var str = "同步成功数量：" + result.successCount;
                            if (result.failCount != 0) {
                                str = str + "  失败数量：" + result.failCount;
                                str = str + result.error;
                            }
                            mini.alert(str);

                            //if (result.res != "操作成功") {
                            //    mini.alert("操作失败!");

                            //}
                            //searchList();
                            grid.reload();
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert(jqXHR.responseText);
                        }
                    });

                } else {
                    mini.alert("请选择要同步的订单!");
                }
            }
            catch (e) {
                mini.alert("请选择要同步的订单!");
                return false;
            }
        }

        function AllocationSupplier() {
            try {
                var rows = grid.getSelecteds();
                if (rows.length > 0) {
                    
                    mini.open({
                        url: "/Ali/pub/SelectSupplier.html",
                        showMaxButton: false,
                        title: "分配供应商",
                        width: 800,
                        height: 500,
                        onload: function () {
                            //打开子页面时传递参数
                            //var iframe = this.getIFrameEl();
                            //var data = { MultiSelect: "false" };
                            //iframe.contentWindow.SetPara(data);
                        },
                        ondestroy: function (action) {
                            //返回数据时的操作
                            if (action == "ok") {
                                var iframe = this.getIFrameEl();
                                var data = iframe.contentWindow.GetData();
                                data = mini.clone(data);
                                if (data) {
                                    for (var i = 0; i < data.length; i++) {
                                        EditAllocationSupplier(data[i].ID);
                                    }
                                }

                            }
                            if (action == "clear") {

                            }

                        }
                    });

                } else {
                    mini.alert("请选择要分配的订单!");
                }
            }
            catch (e) {
                mini.alert("请选择要分配的订单!");
                return false;
            }
        }
        function EditAllocationSupplier(supplierID) {
            var rows = grid.getSelecteds();
            var idArr = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                idArr.push(r.ID);
            }
            var ids = idArr.join(',');
            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=EditAliOrderSupplier",
                data: { ids: ids, supplierID: supplierID },
                cache: false,
                type: 'post',
                success: function (text) {
                    var o = mini.decode(text);
                    var message = o.res;
                    if (o.error != "") {
                        message += "\r\n";// + "错误信息：" + o.error;
                        mini.alert(message);
                    }
                    grid.reload();      // dv_PositionList.reload();

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }
        
        function EditOrder() {
            var rows = grid.getSelecteds();
            //var rows = grid.getSelected();
            if (rows.length > 1) {
                alert("编辑时只能单选");
            }
            else if (rows.length <= 0) {
                alert("请选中一条记录");
            } else {
                mini.open({
                    url: bootPATH + "../Ali/OrderEdit.html",
                    title: "编辑",
                    width: 900,
                    height: 550,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "Update", ID: rows[0].ID };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();

                    }
                });
            }
            //if (row) {
            //    mini.open({
            //        url: bootPATH + "../Ali/OrderEdit.html",
            //        title: "编辑",
            //        width: 900,
            //        height: 550,
            //        onload: function () {
            //            var iframe = this.getIFrameEl();
            //            var data = { action: "Update", ID: row.ID };
            //            iframe.contentWindow.SetData(data);
            //        },
            //        ondestroy: function (action) {
            //            grid.reload();

            //        }
            //    });

            //} else {
            //    alert("请选中一条记录");
            //}
        }
        

        function onDrawCell(e) {
            var column = e.column,
                field = e.field,
                value = e.value,
                node = e.record;
            if (field == "Maintenance") {
                //e.cellHtml = "aaa";
                /*e.cellHtml = "<a onmouseleave=\"CloseTip()\" onmouseover=\"ShowTips(this,'" + node.task_id_ + "','" + node.task_name_ + "','" + node.description_ + "','" + node.assign_user_name_ + "','" + node.manage_user_name_ + "','" + node.status_ + "','" + node.broken_ + "','" + node.estimated_end_time_ + "')\" onclick=\"EditTask('" + node.task_id_ + "')\" href=\"javascript:void(0);\" style=\"color:blue;text-decoration:none;\">" + GetDesignation(value, 16) + "</a>"; //GetDelay(node.estimated_end_time_, node.status_)*/
                //<img src=\"/Static/img/itask/add_icon.png\" onclick=\"ResoleTask()\" />
                //mini.alert(node.ID);
                e.cellHtml = "<a href=\"javascript:void(0);\" onclick=\"ShowMaintenances(" + node.ID + ")\">点击查看</a>";
            }
            else if (field == "enlink") {
                //e.cellHtml = "<a href=\"javascript:void(0);\" onclick=\"ShowLink(" + node.ENid + ")\">点击查看</a>";
                //e.cellHtml = "<a target=\"_blank\" href=\"http://www.aliexpress.com/snapshot/" + node.ENid + ".html?orderId=" + node.OrderId + "\"\">英文链接</a>";
                e.cellHtml = "<a target=\"_blank\" href=\"" + node.ProductSnapshotUrl + "\">英文链接</a>";
            }
            else if (field == "rulink") {
                e.cellHtml = "<a target=\"_blank\" href=\"http://www.aliexpress.com/snapshot/" + node.RUid + ".html?orderId=" + node.OrderId + "\"\">俄文链接</a>";
            }
            else if (field == "ServiceAmount") {
                e.cellHtml = node.ServiceAmount / 100;
            }
            else if (field == "ProductAmount") {
                e.cellHtml = node.ProductAmount / 100;
            }
            else if (field == "ProductType") {
                if (node.ProductType == "5090301") {
                    e.cellHtml = "Phone";
                }
                else if (node.ProductType == "200001086") {
                    e.cellHtml = "Tablet PC";
                } else {
                    e.cellHtml = node.ProductType;
                }
            }
        }
        function ShowMaintenances(id) {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: bootPATH + "../Ali/MaintenanceList.html",
                    title: "维修记录",
                    width: 900,
                    height: 550,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {  OrderID: row.ID };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                        //grid.reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        }
        function AllocationSullpierChange() {
            var id = mini.getbyName("AllocationSullpier").getValue();
            if (id == 1) {
                document.getElementById("supSelect").style.display = "";
            }
            else if (id == 0 || id == "") {
                document.getElementById("supSelect").style.display = "none";
                mini.getbyName("Supplier").setValue("");
            }
        }
        function SaveData() {
            if (grid.isValid() == false) {
                alert("请校验输入单元格内容");
                var error = grid.getCellErrors()[0];
                grid.beginEditCell(error.record, error.column);
                return;
            }
            var rows = grid.getChanges();
            if (rows.length <= 0) {
                alert("没有可保存的项！");
                return;
            }
            var ids = [];
            var imeis = [];
            var sns = [];
            var brands = [];
            var models = [];

            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                ids.push(row.ID);
                imeis.push(row.ProductIMEI);
                sns.push(row.ProductSN);
                brands.push(row.BrandName);
                models.push(row.ProductModel);
            }
            //alert(brands.join('￥'));
            //alert(models.join('￥'));
            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=BatchEditOrder",
                cache: false,
                type: "post",
                data: {
                    ids: ids.join('￥'),
                    imeis: imeis.join('￥'),
                    sns: sns.join('￥'),
                    brands: brands.join('￥'),
                    models: models.join('￥')
                },
                success: function (text) {
                    grid.reload();
                }
            });
        }
        
        //导出表格
        function ExportExcel() {
            var columns = grid.getBottomColumns();

            function getColumns(columns) {
                columns = columns.clone();
                for (var i = columns.length - 1; i >= 0; i--) {
                    var column = columns[i];
                    if (!column.field) {
                        columns.removeAt(i);
                    } else {
                        var c = { header: column.header, field: column.field };
                        columns[i] = c;
                    }
                }
                return columns;
            }
            var columns = getColumns(columns);
            var json = mini.encode(columns);
            document.getElementById("excelData").value = json;
            
            // 隐藏域
            var orderid = trimStr(mini.get("txt_OrderNO").getValue());
            document.getElementById("orderNOHidden").value = orderid;

            var orderDateStart = mini.get("txt_OrderDateStart").getFormValue();
            document.getElementById("orderStartDateHidden").value = orderDateStart;

            var orderDateEnd = mini.get("txt_OrderDateEnd").getFormValue();
            document.getElementById("orderEndDateHidden").value = orderDateEnd;

            var isAllocation = mini.getbyName("AllocationSullpier").getValue();
            document.getElementById("isAllocationHidden").value = isAllocation;
            
            var supplierID = mini.get("supSelect").getValue();
            document.getElementById("supplierIDHidden").value = supplierID;

            var brandName = mini.get("txt_brandName").getValue();
            document.getElementById("brandNameHidden").value = brandName;
            
            var productModel = mini.get("txt_productModel").getValue();
            document.getElementById("productModelHidden").value = productModel;
            
            var warrantyType = mini.getbyName("warrantyTypeSelect").getValue();
            document.getElementById("warrantyTypeSelectHidden").value = warrantyType;
            var serviceStartStart = mini.get("txt_ServiceStartStart").getFormValue();
            document.getElementById("serviceStartStartHidden").value = serviceStartStart;
            var serviceStartEnd = mini.get("txt_ServiceStartEnd").getFormValue();
            document.getElementById("serviceStartEndHidden").value = serviceStartEnd;
            var serviceEndStart = mini.get("txt_ServiceEndStart").getFormValue();
            document.getElementById("serviceEndStartHidden").value = serviceEndStart;
            var serviceEndEnd = mini.get("txt_ServiceEndEnd").getFormValue();
            document.getElementById("serviceEndEndHidden").value = serviceEndEnd;
            var country = mini.get("txt_country").getValue();
            document.getElementById("countryHidden").value = country;
            var effectiveSelect = mini.get("effectiveSelect").getValue();
            document.getElementById("effectiveSelectHidden").value = effectiveSelect;
            var effectiveDateStart = mini.get("txt_EffectiveDateStart").getFormValue();
            document.getElementById("effectiveDateStartHidden").value = effectiveDateStart;
            var effectiveDateEnd = mini.get("txt_EffectiveDateEnd").getFormValue();
            document.getElementById("effectiveDateEndHidden").value = effectiveDateEnd;
            
            var warrantyStatus = mini.get("warrantyStatus").getFormValue();
            document.getElementById("warrantyStatusHidden").value = warrantyStatus;
            

            var productType = mini.getbyName("productType").getValue();
            document.getElementById("productTypeHidden").value = productType;

            var hasIssue = mini.getbyName("hasIssue").getValue();
            document.getElementById("hasIssueHidden").value = hasIssue;


            var excelForm = document.getElementById("excelForm");
            excelForm.submit();
        }
        


    </script>
</body>
</html>
